package com.zcgame.rxjavademo;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;

/**
 * @author:huangLJ
 * @date:2021/6/11 10:30
 */
public class test {
    public static void main(String[] args) {
        Observable.just(getData())
                .flatMap(new Function<List<Student>, ObservableSource<?>>() {
                    @Override
                    public ObservableSource<?> apply(List<Student> students) {
                        return Observable.fromIterable(students);
                    }
                })
                .subscribe(t -> {
                    Log.d("=====", t.toString());
                });
    }
    private static List<Student> getData() {
        List<Student> data = new ArrayList<>();
        Student stu = null;
        for (int i = 0; i < 5; i ++) {
            stu = new Student();
            stu.name = "学生" + i;
            stu.no = i;
            data.add(stu);
        }
        return data;
    }


    public static class Student {
        public String name;
        public int no;
    }
}
